import LevelBaseControl from "../LevelCommon/LevelBaseControl";
import RotateObj from "../Prefabs/InteractivObj/Common/RotateObj";
import MoveObj from "../Prefabs/InteractivObj/Common/MoveObj";
import Gate from "../Prefabs/InteractivObj/Gate";
import GamePropConst from "../../constant/GamePropConst";
import DialogDataConst from "../../constant/DialogDataConst";
import Sound from "../../constant/SoundNameConstant";
import InteractiveBase from "../LevelCommon/InteractiveBase";
import EnumData from "../../Enum/EnumData";
import GamePanel from "../Panel/GamePanel";
import { GamePropData } from "../Data/GamePropData";

export default class LevelControl9 extends LevelBaseControl {

    /** 地板盖子是否打开了*/
    private isOpenGaiZi: boolean = false;
    /** 地板盖子*/
    private gaiziRotateObj: RotateObj;
    /** 没有燃烧的木材*/
    private wooden: Laya.Sprite3D;
    /** 燃烧过的木材*/
    private burnWooden: Laya.Sprite3D;
    /** 燃烧木材特效*/
    private burnFire: Laya.Sprite3D;
    /** 木盒*/
    private woodBox: Laya.Sprite3D;
    /** 是否少了木盒*/
    private isFireBox: boolean = false;
    /** 轮盘盖子*/
    private rouletteGaiZi: RotateObj;
    /** 轮盘盖子是否打开了*/
    private isOpenRoulet: boolean = false;
    /** 老虎机上裝的轮盘*/
    private laohu_head_Roulette: Laya.Sprite3D;
    /** 摇杆*/
    private Joystick: RotateObj;
    /** 是否摇过摇杆了*/
    private isHaveJoystick: boolean = false;
    /** 日历表*/
    private rili: MoveObj;
    /** 扑克密码是否解开了*/
    private isPukeOpen: boolean = false;
    /** 第二个期棋盘*/
    private secondChess: Laya.Sprite3D;
    /** 硬币*/
    private finalChessCoin: Laya.Sprite3D;
    /** 第二个棋盘是否解锁了*/
    private isOpenSecondCess: boolean = false;
    /** 最后的大门是否打开了*/
    private isOpenFinalGate: boolean = false;
    /** 最终的门*/
    private finalGate: Gate;
    /** 三个拉拔机的动画*/
    public joyAnimators: Laya.Animation;

    protected startByBase() {

        let room1 = this.allLevelObjs[0].owner;
        let Container = room1.getChildByName("Container");
        let walls = room1.getChildByName("walls");
        let wall1 = walls.getChildByName("wall1");
        let wall2 = walls.getChildByName("wall2");
        let wall3 = walls.getChildByName("wall3");
        let wall4 = walls.getChildByName("wall4");

        this.gaiziRotateObj = Container.getChildByName("gaizi").getChildByName("gaizi").getComponent(RotateObj);

        this.wooden = wall2.getChildByName("ChamferBox001").getChildByName("GameObject").getChildByName("wood") as Laya.Sprite3D;


        this.burnWooden = wall2.getChildByName("ChamferBox001").getChildByName("GameObject").getChildByName("burnWood") as Laya.Sprite3D;

        this.burnFire = wall2.getChildByName("ChamferBox001").getChildByName("GameObject").getChildByName("fire") as Laya.Sprite3D;


        this.woodBox = wall2.getChildByName("ChamferBox001").getChildByName("GameObject").getChildByName("woodBox") as Laya.Sprite3D;

        this.rouletteGaiZi = wall1.getChildByName("Roulette").getChildByName("head_Roulette").getComponent(RotateObj);

        this.laohu_head_Roulette = wall4.getChildByName("Box012").getChildByName("laohu_head_Roulette") as Laya.Sprite3D;

        this.Joystick = wall4.getChildByName("Box012").getChildByName("Joystick").getComponent(RotateObj);

        this.rili = wall4.getChildByName("Box012").getChildByName("rili").getComponent(MoveObj);

        this.secondChess = Container.getChildByName("finalChess") as Laya.Sprite3D;

        this.finalChessCoin = this.secondChess.getChildByName("finalChess_coin") as Laya.Sprite3D;

        this.finalGate = wall3.getChildByName("SM_Bld_Bunker_Wall_Caution_Door_01").getChildByName("SM_Bld_Bunker_Wall_Caution_Door_Opening_01").getComponent(Gate);

    }

    public DoInteractObjLogic(_name: string): boolean {
        switch (_name) {
            /** 判断选择道具 打开地板盖子*/
            case "gaiziCollier":
                if (!this.isOpenGaiZi && this.IsSelectProp(GamePropConst.Hoop_prop)) {
                    this.gaiziRotateObj.Interactive();
                    this.isOpenGaiZi = true;
                }
                else {
                    if (!this.isOpenGaiZi) {
                        /** 无法打开*/
                        this.ShowDialog(DialogDataConst.cannt_open);
                    }
                }
                break;
            /** 木盒  没打开地板就无法获得*/
            case "SM_Prop_Crate_01":
                if (!this.isOpenGaiZi) {
                    return false;
                }
                break;
            /** 点击木材 判断选择了火柴 燃烧*/
            case "wood":
                if (this.IsSelectProp(GamePropConst.mathces_prop)) {
                    /** 使用火柴*/
                    this.UseCurProp();
                    /** 显示火*/
                    this.burnFire.active = true;
                    window.gameFacade.SoundMng.playSound(Sound.soundClipArr.FIRE);
                    this.wooden.getComponent(InteractiveBase).parentInteractive.SetAllSonObj();
                }
                break;
            /** 点了火 判断有木盒 烧木盒 如果烧了木盒 判断有水 浇灭*/
            case "fire":
                if (!this.isFireBox) {
                    if (this.IsSelectProp(GamePropConst.wooden_box)) {
                        /** 使用木盒*/
                        this.UseCurProp();
                        this.woodBox.active = true;
                        /** 延时消失*/
                        Laya.timer.once(2000, this, this.FireFinishBox);

                        /** 烧完前不能有ui操作  创建一个遮罩*/
                        let gamePanel = window.gameFacade.SceneMng.GetPanelById(EnumData.EnumPanelType.GamePanel) as GamePanel;
                        gamePanel.ShowMaskImageAndAutoHide(2000, this, null);
                        this.isFireBox = true;
                    }
                }
                else /** 烧过箱子了*/ {
                    if (this.IsSelectProp(GamePropConst.water_bottle)) {
                        /** 使用水瓶*/
                        this.UseCurProp();
                        this.BurnOutWooden();
                    }
                    else {
                        /** 提示里面有东西*/
                        this.ShowDialog(DialogDataConst.get_in_garbon_tip);
                    }
                }
                break;
            /** 点了烧过的碳 判断有钩子 拿到硬币*/
            case "burnWood":
                if (this.IsSelectProp(GamePropConst.Hoop_prop)) {
                    let propData: GamePropData = window.gameFacade.ConfigMng.GetGamePropDataById(GamePropConst.coin_prop);
                    /** 获得硬币*/
                    this.GetGameProp(propData);
                    this.burnWooden.active = true;
                }
                else {
                    /** 提示里面有东西*/
                    this.ShowDialog(DialogDataConst.get_in_garbon_tip);
                }
                break;
            /** 点击轮盘下的硬币 如果轮盘打开了就获得 不然就不获得*/
            case "rouletCoin":
                if (!this.isOpenRoulet) {
                    return false;
                }
                break;
            /** 点击轮盘 如果轮盘打开了就获得 不然就不获得*/
            case "head_Roulette":
                if (!this.isOpenRoulet) {
                    return false;
                }
                break;
            /** 轮盘密码正确 打开轮盘盖子*/
            case "physPassLock_UnLock":
                this.rouletteGaiZi.Interactive();
                this.isOpenRoulet = true;
                break;
            /** 点击了摇杆 如果装上了轮盘 而且没有转过 就摇下来*/
            case "Joystick":
                if (!this.laohu_head_Roulette.activeInHierarchy || this.isHaveJoystick) {
                    if (!this.laohu_head_Roulette.activeInHierarchy) {
                        this.ShowDialog(DialogDataConst.joystick_tip);
                    }
                    return false;
                }
                /** 摇摇杆*/
                this.isHaveJoystick = true;
                window.gameFacade.SoundMng.playSound(Sound.soundClipArr.LA_ZHA);
                //   foreach (Animation item in joyAnimators)
                //   {
                //       item.Play();
                //   }
                Laya.timer.once(700, this, this.RiliOut);
                break;
            /** 点击老虎机轮盘位置 检测选中了轮盘道具 装上去*/
            case "rouletteCheck":
                if (this.IsSelectProp(GamePropConst.Roulette)) {
                    this.UseCurProp();
                    this.laohu_head_Roulette.active = true;
                }
                break;
            /** 解开了扑克机关*/
            case "physPassLock_puke_UnLock":
                this.isPukeOpen = true;
                break;
            /** 扑克机关下的硬币 解开了才能获得*/
            case "rouletCoin_puke":
                if (!this.isPukeOpen) {
                    return false;
                }
                break;
            /** 第一个棋盘解锁了 显示第二个*/
            case "firstChess_UnLock":
                this.ShowDialog(DialogDataConst.open_chess);
                this.secondChess.active = true;
                break;
            /** 最后一个棋盘解锁*/
            case "chess_side_Lock_UnLock":
                this.finalChessCoin.active = true;
                this.isOpenSecondCess = true;
                break;
            /** 棋盘下的硬币 要解锁了最后一个棋盘才能获得*/
            case "finalChess_coin":
                if (!this.isOpenSecondCess) {
                    return false;
                }
                break;
            /** 点击了硬币机器的按钮 打开最后的大门*/
            case "coinMachineBtn":
                if (!this.isOpenFinalGate) {
                    this.finalGate.SetOpen();
                    this.ShowDialog(DialogDataConst.open_gate);
                    this.isOpenFinalGate = true;
                }
                break;
            /** 进入最后的大门 过关*/
            case "SM_Bld_Bunker_Wall_Caution_Door_Opening_01_In_Gate":
                this.FinishLevel();
                break;
            default:
                break;
        }
        return true;
    }
    /** 木材烧完了 灭火*/
    private BurnOutWooden() {
        this.burnWooden.active = true;
        this.woodBox.active = false;
        this.wooden.getComponent(InteractiveBase).parentInteractive.SetAllSonObj();
        this.burnFire.active = false;
        this.wooden.active = false;
    }
    private RiliOut() {
        /** 日历划出来出来*/
        this.rili.Interactive();
    }
    /** 木盒延时消失*/
    private FireFinishBox() {
        this.woodBox.active = false;
    }
}